package cn.ibizlab.core.authentication.service.impl;

import cn.ibizlab.core.authentication.service.CaptchaService;
import com.google.code.kaptcha.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import java.awt.image.BufferedImage;

/**
 * google kaptcha 验证码服务
 */
@Service
@ConditionalOnExpression("'${ibiz.auth.imageCaptcha.enable:false}'.equals('true') && '${ibiz.auth.imageCaptcha.service:kaptcha}'.equals('kaptcha')")
public class KaptchaService implements CaptchaService {

    @Autowired
    private Producer captchaProducer;

    @Override
    public String createText() {
        return captchaProducer.createText();
    }

    @Override
    public BufferedImage createImage(String text) {
        return captchaProducer.createImage(text);
    }

}
